Last updated: 2023-07-31
Checks: 5 1
Knit directory: WenjunLiu_Thesis_Chapter4/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20200930) was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Tracking code development and connecting the code version to the
results is critical for reproducibility. To start using Git, open the
Terminal and type git init in your project directory.
This project is not being versioned with Git. To obtain the full
reproducibility benefits of using workflowr, please see
?wflow_start.
library(ngsReports)
library(tidyverse)
library(yaml)
library(scales)
library(pander)
library(glue)
library(cowplot)
library(plotly)
panderOptions("table.split.table", Inf)
panderOptions("big.mark", ",")
theme_set(theme_bw())
config <- here::here("config/config.yml") %>%
read_yaml()
suffix <- paste0(config$tag, config$ext)
sp <- config$ref$species %>%
str_replace("(^[a-z])[a-z]*_([a-z]+)", "\\1\\2") %>%
str_to_title()
samples <- config$samples %>%
here::here() %>%
read_tsv() %>%
mutate(
Filename = paste0(sample, suffix)
) %>%
mutate_if(
function(x){length(unique(x)) < length(x)},
as.factor
)
config$analysis <- config$analysis %>%
lapply(intersect, y = colnames(samples)) %>%
.[vapply(., length, integer(1)) > 0]
if (length(config$analysis)) {
samples <- samples %>%
unite(
col = group,
any_of(as.character(unlist(config$analysis))),
sep = "_", remove = FALSE
)
} else {
samples$group <- samples$Filename
}
group_cols <- hcl.colors(
n = length(unique(samples$group)),
palette = "Zissou 1"
) %>%
setNames(unique(samples$group))
In the workflow, trimming was performed using the tool
AdapterRemoval with the settings:
N bases to allow: 1rawFqc <- here::here("data/raw/FastQC") %>%
list.files(pattern = "zip", full.names = TRUE) %>%
FastqcDataList() %>%
.[fqName(.) %in% samples$Filename]
trimFqc <- here::here("data/trimmed/FastQC") %>%
list.files(pattern = "zip", full.names = TRUE) %>%
FastqcDataList() %>%
.[fqName(.) %in% samples$Filename]
After trimming, the library showing the highest level of possible adapter content contained 0.15% of reads as containing possible adapter sequences.
a <- plotSummary(rawFqc, pattern = suffix) +
theme(axis.text.y=element_blank())
b <- plotSummary(trimFqc, pattern = suffix) +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank()
)
plot_grid(
a + theme(legend.position = "none"),
b + theme(legend.position = "none"),
labels = c("A", "B"),
nrow = 1,
rel_widths = c(1.6, 1)
) +
draw_plot(
plot = get_legend(a),
x = -0.3,
y = -0.4,
)
Comparison of FastQC summaries A) before and B), after trimming
readTotals(rawFqc) %>%
rename(Raw = Total_Sequences) %>%
left_join(
readTotals(trimFqc) %>%
rename(Trimmed = Total_Sequences)
) %>%
mutate(
Remaining = Trimmed / Raw,
Filename = str_remove_all(Filename, suffix)
) %>%
summarise(
across(c(Remaining, Trimmed), list(min = min, mean = mean, max = max))
) %>%
pivot_longer(
everything()
) %>%
separate(
name, into = c("Type", "Summary Statistic")
) %>%
pivot_wider(names_from = Type, values_from = value) %>%
mutate(
Remaining = percent(Remaining, accuracy = 0.1),
`Summary Statistic` = str_to_title(`Summary Statistic`)
) %>%
rename(Reads = Trimmed) %>%
pander(
caption = "*Summary statistics showing the results after trimming*"
)
| Summary Statistic | Remaining | Reads |
|---|---|---|
| Min | 96.2% | 947,500 |
| Mean | 97.0% | 2,167,361 |
| Max | 97.7% | 5,995,508 |
ggplotly(
getModule(trimFqc, "Sequence_Length") %>%
group_by(Filename) %>%
mutate(
`Cumulative Total` = cumsum(Count),
`Cumulative Percent` = percent(`Cumulative Total` / max(`Cumulative Total`))
) %>%
ungroup() %>%
left_join(samples) %>%
rename_all(str_to_title) %>%
ggplot(aes(Length, `Cumulative Total`, group = Filename, label = `Cumulative Percent`)) +
geom_line(aes(colour = Group), size = 1/4) +
scale_y_continuous(label = comma) +
scale_colour_manual(
values = group_cols
)
)
Distribution of read lengths after trimming
ggplotly(
getModule(trimFqc, "Per_sequence_GC_content") %>%
group_by(Filename) %>%
mutate(
cumulative = cumsum(Count) / sum(Count)
) %>%
ungroup() %>%
left_join(samples) %>%
bind_rows(
getGC(gcTheoretical, sp, "Trans") %>%
mutate_at(sp, cumsum) %>%
rename_all(
str_replace_all,
pattern = sp, replacement = "cumulative",
) %>%
mutate(
Filename = "Theoretical GC",
group = Filename
)
) %>%
mutate(
group = as.factor(group),
group = relevel(group, ref = "Theoretical GC"),
cumulative = round(cumulative*100, 2)
) %>%
ggplot(aes(GC_Content, cumulative, group = Filename)) +
geom_line(aes(colour = group), size = 1/4) +
scale_x_continuous(label = ngsReports:::.addPercent) +
scale_y_continuous(label = ngsReports:::.addPercent) +
scale_colour_manual(
values = c("#000000", group_cols)
) +
labs(
x = "GC Content",
y = "Cumulative Total",
colour = "Group"
)
)
GC content shown as a cumulative distribution for all libraries. Groups can be hidden by clicking on them in the legend.
plotly::ggplotly(
getModule(trimFqc, module = "Per_base_sequence_content") %>%
mutate(Base = fct_inorder(Base)) %>%
group_by(Base) %>%
mutate(
across(c("A", "C", "G", "T"), function(x){x - mean(x)})
) %>%
pivot_longer(
cols = c("A", "C", "G", "T"),
names_to = "Nuc",
values_to = "resid"
) %>%
left_join(samples) %>%
ggplot(
aes(Base, resid, group = Filename, colour = group)
) +
geom_line() +
facet_wrap(~Nuc) +
scale_colour_manual(values = group_cols) +
labs(
x = "Read Position", y = "Residual", colour = "Group"
)
)